//
// common.h
//
// This file contains the OS dependant definition and function.
// Every OS has this file individual.
//

#define DebugUsbdStatusInformation( _A )

#ifndef COMMON_DEF
#define COMMON_DEF

#include <linux/version.h>
#include <linux/usb.h>
#include <linux/kernel.h> //need for kernel alert
#include <linux/autoconf.h>
#include <linux/sched.h>
#include <linux/signal.h>
#include <linux/slab.h> //memory allocate
#include <linux/module.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/init.h>//need for init and exit modules marco
#include <linux/ctype.h> 
#include <linux/wait.h>
#include <linux/list.h>
#include <linux/wireless.h>
#include <linux/if_arp.h>
#include <asm/uaccess.h>
#include <net/iw_handler.h>
#include <linux/skbuff.h>


//#define DEBUG_ENABLED  1



//==================================================================================================
// Common type definition
//==================================================================================================
typedef u8		UCHAR;
typedef u16		USHORT;
typedef u32		ULONG;
typedef u8		BOOL;
typedef s8		CHAR;

typedef u8*		PUCHAR;
typedef s8*		PCHAR;
typedef u8*		PBOOLEAN;
typedef u16*		PUSHORT;
typedef u32*		PULONG;

typedef u32		UINT;//$
typedef u64		ULONG64;
typedef s32		LONG;
typedef s32		INT;//$
typedef s16		SHORT;
typedef s16*	PSHORT;

#define STATIC	static

#define PVOID	void*
#define IN		
#define OUT		

//===========================================
#define IGNORE      2
#define	SUCCESS     1
#define	FAILURE     0

#define U8      unsigned char
#define U16     unsigned short
#define U32     unsigned long

#define S8      char
#define S16     short
#define S_32     long

#define u8      unsigned char
#define u16     unsigned short
#define u32     unsigned long

#define s8      char
#define s16     short
#define s32     long

#define	VOID    void
#define	BOOL    unsigned char
#define	BOOLEAN unsigned char

#define size_t  unsigned long

#ifndef true
#define true        1
#endif

#ifndef false
#define false       0
#endif

// PD43 20021108
#ifndef TRUE
#define TRUE        1
#endif

#ifndef FALSE
#define FALSE       0
#endif

#define STATUS_MEDIA_CONNECT 1
#define STATUS_MEDIA_DISCONNECT 0

#ifndef BIT
#define BIT(x)                  (1 << (x))
#endif 

typedef struct urb * PURB;
typedef int	URB_STATUS;



//==================================================================================================
// Common function definition
//==================================================================================================
#ifndef abs
#define abs(_T)							((_T) < 0 ? -_T : _T)   //Added by wangJS 2006.7.25
#endif
#define DEBUG_ENABLED
#define ETH_LENGTH_OF_ADDRESS	6
#ifdef DEBUG_ENABLED
#define WBDEBUG( _M )	printk _M
#else
#define WBDEBUG( _M )	0
#endif

// #define OS_PACKET_SIZE( _A )						<-- Supported. In WbLinux module
// #define OS_LINK_STATUS							<-- Supported. In WbLinux module
// #define OS_SET_SHUTDOWN( _A )					<-- Supported. In WbLinux module
// #define OS_CONNECT_STATUS_INDICATE( _A, _F )		<-- Supported. In WbLinux module
#define OS_DISCONNECTED	0
#define OS_CONNECTED	1
// #define OS_STOP( _A )							<-- Supported. In WbLinux module

// #define OS_CURRENT_RX_BYTE( _A )					<-- Supported. In WbLinux module
// #define OS_CURRENT_TX_BYTE( _A )					<-- Supported. In WbLinux module
#define OS_EVENT_INDICATE( _A, _B, _F )
#define OS_PMKID_STATUS_EVENT( _A )
// #define OS_RECEIVE_PACKET_INDICATE( _A, _D )		<-- Supported. In WbLinux module
// #define OS_GET_PACKET( _A, _D )					<-- Supported. In WbLinux module
// #define OS_GET_PACKET_COMPLETE( _A, _D )			<-- Supported. In WbLinux module

// #define cpu_to_le32( _A )			<-- Supported. Linux OS
// #define cpu_to_le16( _A )			<-- Supported. Linux OS
#define __ALIGN_PACK__                  __attribute__ ((packed))

#define OS_ATOMIC						ULONG
#define OS_ATOMIC_READ( _A, _V )		_V
#define OS_ATOMIC_INC( _A, _V )			EncapAtomicInc( _A, (PVOID)_V )
#define OS_ATOMIC_DEC( _A, _V )			EncapAtomicDec( _A, (PVOID)_V )
// #define OS_MEMORY_ALLOC( _V, _S )		<--- Supported in WbLinux module
#define OS_MEMORY_FREE( _V, _S )		kfree( _V )
#define	OS_MEMORY_ALLOC_OK				1
#define	OS_MEMORY_ALLOC_FAIL			0
#define OS_MEMORY_COPY( _T, _S, _SIZE )	memcpy( (PUCHAR) _T, _S, _SIZE ) //NdisMoveMemory( _T, _S, _SIZE )
#define OS_MEMORY_CLEAR( _A, _S )		memset( (PUCHAR)_A,0,_S)
#define OS_MEMORY_COMPARE( _A, _B, _S )	(memcmp(_A,_B,_S)? 0 : 1) // Definition is reverse with Ndis 1: the same 0: different
#define OS_DELAY( _MT )					//NdisStallExecution( _MT ) _MT : microsecond
//#define OS_SLEEP( _MT )					<--- Supported in WbUsb module

#define OS_SPIN_LOCK					spinlock_t//NDIS_SPIN_LOCK
#define OS_SPIN_LOCK_ALLOCATE( _S )		spin_lock_init( _S ); //NdisAllocateSpinLock( _S )	
#define OS_SPIN_LOCK_FREE( _S )			//NdisFreeSpinLock( _S )
#define OS_SPIN_LOCK_ACQUIRED( _S )		spin_lock_irq( _S )
#define OS_SPIN_LOCK_RELEASED( _S )		spin_unlock_irq( _S ); //NdisReleaseSpinLock( _S )

#define OS_TIMER						struct timer_list
#define OS_TIMER_INITIAL( _T, _F, _P )			\
{												\
	init_timer( _T );							\
	(_T)->function = (void *)_F##_1a;			\
	(_T)->data = (unsigned long)_P;				\
}
// _S : Millisecond
// 20060420 At least 1 large than jiffies
#define OS_TIMER_SET( _T, _S )					\
{												\
	(_T)->expires = jiffies + ((_S*HZ+999)/1000);\
	add_timer( _T );							\
}
#define OS_TIMER_CANCEL( _T, _B )		del_timer_sync( _T ) //NdisMCancelTimer( _T, _B )
#define OS_TIMER_GET_SYS_TIME( _T )		(*_T=jiffies)


#endif // COMMON_DEF

